package middleware

import (
	"log"

	"github.com/gin-gonic/gin"
)

func Middleware1() gin.HandlerFunc {
	return func(ctx *gin.Context) {
		log.Println("middleware1 before")

		// 处理下一个 handler
		ctx.Next()

		log.Println("middleware1 after")
	}
}

func Middleware2() gin.HandlerFunc {
	return func(ctx *gin.Context) {
		log.Println("middleware2 before")

		// 如果请求没有带 operator 参数，则不用执行后续的
		if ctx.GetHeader("operator") == "" {
			ctx.Abort()
			log.Println("middleware2 after Abort()")
		}

		// 处理下一个 handler
		ctx.Next()

		log.Println("middleware2 after")
	}
}

func Middleware3() gin.HandlerFunc {
	return func(ctx *gin.Context) {
		log.Println("middleware3 before")

		// 处理下一个 handler
		ctx.Next()

		log.Println("middleware3 after")
	}
}
